﻿/*2015*/
define(['cPageView','cMemberService', 'cUtility','cUtilCryptBase64','cGuiderService', 'cHybridFacade'], function ( BasePageView,cMemberService,cUtility,cUtilCryptBase64,cGuiderService,Facade) {
    'use strict';
    var shareLink = window.location.protocol + "//" + window.location.hostname + window.location.pathname+window.location.search;
    var fromLink=window.encodeURIComponent(shareLink);
    var vHeight=$(window).height();
    var isInApp =  Lizard.isHybrid || Lizard.isInCtripApp;
    var currentActiveIdx=0;
    var View = BasePageView.extend({
        pageid:'',
        hpageid:'',
        render: function (html) {
            this.$el.html(html);    
        },
        fnSearchLog: function (sText, sId) {
            if (!sText) return;
            if (typeof window['__bfi'] == 'undefined') window['__bfi'] = [];
            window['__bfi'].push(['_tracklog', sId, sText]);
        },
        appShare: function () {
            var self = this,
                imgUrl = '',
                suffix = 'jpg',
                text = '日本樱花签证',
                shareTitle = [''],
                len = shareTitle.length,
                random = parseInt(Math.random() * len),
                index = random >= len ? len - 1 : random,
                title = shareTitle[index],
                shareUrl = shareLink;

            //app中分享加密
            var ctripShare = CtripBusiness.app_call_system_share || CtripUtil.app_call_system_share;
            cGuiderService.downloadData({
                callback: function (data) {
                    ctripShare(data.savedPath, title, text, shareUrl, false);
                },
                url: imgUrl,
                suffix: suffix
            });
        },
        setHead: function () {
            var self = this;
            this.headerview.set({
                title: '日本樱花签证',
                back: true,
                view: this,
                home: false,
                share: true,
                events: {
                    returnHandler: function () {
//                        CtripUtil.app_back_to_home();
                        CtripUtil.app_back_to_last_page();
//                          self.jump("http://pages.dev.sh.ctriptravel.com/commerce/promote/201507/vacation/qtots/qotsh5_cs.html");

                    }
                }
            });
            cGuiderService.register({
                tagname: Facade.METHOD_SHARE, callback: function () {
                    self.appShare();
                }
            });
        },
        setFlipEvents: function () {
            var self=this;
            var pageLen=$(".page").length;
            _.flip($(".flip-cnt"), "up", function (e) {
                if(currentActiveIdx>=pageLen-1){
                    return;
                }
                currentActiveIdx++;
                $(".flip-cnt").get(0).style.webkitTransform='translateY('+(-currentActiveIdx*vHeight)+'px)';
            }, false, 0,50);
             _.flip($(".flip-cnt"), "down", function (e) {
                if(currentActiveIdx<=0){
                    return;
                }
                currentActiveIdx--;
                $(".flip-cnt").get(0).style.webkitTransform='translateY('+(-currentActiveIdx*vHeight)+'px)';
            }, false, 0,50);
        },
        onShow: function () {
            var self = this;            
            if (isInApp) {
                this.setHead();
            }

            //微信分享话术设置
            if (navigator.userAgent.toLowerCase().indexOf('micromessenger') > -1) {
                document.title='日本樱花签证';
            } 
            /*这里可以添加您的业务逻辑代码 开始*/     
        
		$("#shanghai1").click(function(){
          self.fnSearchLog ('','shanghai1')
                  if(isInApp){
                      CtripUtil.app_open_url('http://m.ctrip.com/webapp/tourvisa/visa_detail?productid=49336&salecityid=2&departcityid=2', 2, "", null);
                  }else{
                      location.href = 'http://m.ctrip.com/webapp/tourvisa/visa_detail?productid=49336&salecityid=2&departcityid=2';
                  }
        });
        $("#shanghai2").click(function(){
          self.fnSearchLog ('','shanghai2')
                  if(isInApp){
                      CtripUtil.app_open_url('http://m.ctrip.com/webapp/tourvisa/visa_detail?productid=2491559&salecityid=2&departcityid=2', 2, "", null);
                  }else{
                      location.href = 'http://m.ctrip.com/webapp/tourvisa/visa_detail?productid=2491559&salecityid=2&departcityid=2';
                  }
        });
        $("#shanghai3").click(function(){
          self.fnSearchLog ('','shanghai3')
                  if(isInApp){
                      CtripUtil.app_open_url('http://m.ctrip.com/webapp/tourvisa/visa_detail?productid=59607&salecityid=2&departcityid=2', 2, "", null);
                  }else{
                      location.href = 'http://m.ctrip.com/webapp/tourvisa/visa_detail?productid=59607&salecityid=2&departcityid=2';
                  }
        });
        $("#shanghai4").click(function(){
          self.fnSearchLog ('','shanghai4')
                  if(isInApp){
                      CtripUtil.app_open_url('http://m.ctrip.com/webapp/tourvisa/visa_detail?productid=2491605&salecityid=2&departcityid=2', 2, "", null);
                  }else{
                      location.href = 'http://m.ctrip.com/webapp/tourvisa/visa_detail?productid=2491605&salecityid=2&departcityid=2';
                  }
        });
        $("#beijing1").click(function(){
          self.fnSearchLog ('','beijing1')
                  if(isInApp){
                      CtripUtil.app_open_url('http://m.ctrip.com/webapp/tourvisa/visa_detail?productid=52838&salecityid=1&departcityid=1', 2, "", null);
                  }else{
                      location.href = 'http://m.ctrip.com/webapp/tourvisa/visa_detail?productid=52838&salecityid=1&departcityid=1';
                  }
        });
        $("#beijing2").click(function(){
          self.fnSearchLog ('','beijing2')
                  if(isInApp){
                      CtripUtil.app_open_url('http://m.ctrip.com/webapp/tourvisa/visa_detail?productid=3163778&salecityid=1&departcityid=1', 2, "", null);
                  }else{
                      location.href = 'http://m.ctrip.com/webapp/tourvisa/visa_detail?productid=3163778&salecityid=1&departcityid=1';
                  }
        });
        $("#beijing3").click(function(){
          self.fnSearchLog ('','beijing3')
                  if(isInApp){
                      CtripUtil.app_open_url('http://m.ctrip.com/webapp/tourvisa/visa_detail?productid=2259082&salecityid=1&departcityid=1', 2, "", null);
                  }else{
                      location.href = 'http://m.ctrip.com/webapp/tourvisa/visa_detail?productid=2259082&salecityid=1&departcityid=1';
                  }
        });
        $("#beijing4").click(function(){
          self.fnSearchLog ('','beijing4')
                  if(isInApp){
                      CtripUtil.app_open_url('http://m.ctrip.com/webapp/tourvisa/visa_detail?productid=2477470&salecityid=1&departcityid=1', 2, "", null);
                  }else{
                      location.href = 'http://m.ctrip.com/webapp/tourvisa/visa_detail?productid=2477470&salecityid=1&departcityid=1';
                  }
        });
        $("#beijing5").click(function(){
          self.fnSearchLog ('','beijing5')
                  if(isInApp){
                      CtripUtil.app_open_url('http://m.ctrip.com/webapp/tourvisa/visa_detail?productid=4915995&salecityid=1&departcityid=1', 2, "", null);
                  }else{
                      location.href = 'http://m.ctrip.com/webapp/tourvisa/visa_detail?productid=4915995&salecityid=1&departcityid=1';
                  }
        });
        $("#chongqing1").click(function(){
          self.fnSearchLog ('','chongqing1')
                  if(isInApp){
                      CtripUtil.app_open_url('http://m.ctrip.com/webapp/tourvisa/visa_detail?productid=91524&salecityid=28&departcityid=28', 2, "", null);
                  }else{
                      location.href = 'http://m.ctrip.com/webapp/tourvisa/visa_detail?productid=91524&salecityid=28&departcityid=28';
                  }
        });
        $("#guangzhou1").click(function(){
          self.fnSearchLog ('','guangzhou1')
                  if(isInApp){
                      CtripUtil.app_open_url('http://m.ctrip.com/webapp/tourvisa/visa_detail?productid=57493&salecityid=32&departcityid=32', 2, "", null);
                  }else{
                      location.href = 'http://m.ctrip.com/webapp/tourvisa/visa_detail?productid=57493&salecityid=32&departcityid=32';
                  }
        });
        $("#guangzhou2").click(function(){
          self.fnSearchLog ('','guangzhou2')
                  if(isInApp){
                      CtripUtil.app_open_url('http://m.ctrip.com/webapp/tourvisa/visa_detail?productid=57493&salecityid=32&departcityid=32', 2, "", null);
                  }else{
                      location.href = 'http://m.ctrip.com/webapp/tourvisa/visa_detail?productid=57493&salecityid=32&departcityid=32';
                  }
        });
        $("#xq_nav").click(function(){
          self.fnSearchLog ('','xq_nav')
                  if(isInApp){
                      CtripUtil.app_open_url('http://m.ctrip.com/events/ribenmenghuanshangyingjishangyingchengshizhoubianjiudian5zheqixianshicuxiaoyidongduan.html', 2, "", null);
                  }else{
                      location.href = 'http://m.ctrip.com/events/ribenmenghuanshangyingjishangyingchengshizhoubianjiudian5zheqixianshicuxiaoyidongduan.html';
                  }
        });
		
            //设置单个滚屏页面的高度              
//            $(".page,.fixed-view").height(vHeight);
            //绑定滑动事件
//            self.setFlipEvents();
            //
//          $('.hot_spring_main li').hover(function(){
//              $(this).find('.pcimg').hide()
//          },function(){
//              $('.pcimg').show()
//          })
            /*这里可以添加您的业务逻辑代码 结束*/
        }
    });
    return View;
});